<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\Log;

/**
 * wo回调接口
 */
class Wocallback extends Api
{

    protected $noNeedLogin = ['*'];

    public function kaoqing() {
        
        if ($_SERVER['REQUEST_METHOD'] != 'POST') {
            Log::write('非法回调');
            exit;
        }

        //2.获取query请求的字节流，对 Query 参数按照字典对 Key 进行排序后,按照value1+value2方法拼接
        $params = $_POST;

        Log::write('参数：'.json_encode($params, true));

        $data = json_decode($params['eventMsg'], true);
        $data['eventGuid'] = $params['eventGuid'];
    
        if($data['timestamp']) {
            $data['timestamp'] = intval($data['timestamp'] / 1000);
        }

        if($data['showTime']) {
            $data['showTime'] = intval($data['showTime'] / 1000);
        }

        if($data['executeTime']) {
            $data['executeTime'] = intval($data['executeTime'] / 1000);
        }
        
        Log::write('data4：'.json_encode($data, true));
        $num = \app\admin\model\dts\attendance\Log::where('eventGuid', $data['eventGuid'])->count(1);
        if($num <= 0) {
            \app\admin\model\dts\attendance\Log::create($data);
        }
        
        $this->success();
    }
}